package game;

import javax.swing.ImageIcon;
import javax.swing.JLabel;

public class Mj extends JLabel implements Comparable<Mj>{
	int type;
	int number;
	boolean isFront=true;   //是否正面
	boolean isSelect=false;		//是否选中
	int x,y;		   //x,y位置
	String imgurl;     //牌的图片
	
	public Mj(int type, int number) {
		this.type = type;
		this.number = number;
		switch (type) {
		case 1:
			imgurl="imgs/bamboo"+number+".png";
			break;
		case 2:
			imgurl="imgs/pin"+number+".png";
			break;
		case 3:
			imgurl="imgs/man"+number+".png";
			break; 
		}
	}

	@Override
	public String toString() {
		String[] hua = {"","条","筒","萬"};
		return number+hua[type];
	} 

	@Override
	public int compareTo(Mj o) {
		if(this.type == o.type) {
			return this.number - o.number;
		}else {
			return this.type - o.type;
		}
	}
	
	@Override
	public boolean equals(Object obj) {
		Mj o=(Mj)obj;
		if(o.type == this.type && o.number==this.number) {
			return true;
		}else {
			return false;
		} 
	}
	
	//显示图片
	public void showPic(boolean p) {
		this.isFront=p;
		ImageIcon pic=null;
		if (isFront) {  //正面
			pic= new ImageIcon(imgurl);
		}else {
			pic= new ImageIcon("imgs/back.png");
		}
		this.setIcon(pic);
	}
	
	public void up() {
		if(this.isSelect) {
			System.out.println("你想出牌"+this);
		}else {
			this.setLocation(x, y-20);
		}
		this.isSelect =!isSelect;
	}
	
	public void down() {
		this.setLocation(x, y);
		this.isSelect =false;
	}
	
	
}